/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func getIntersectionNode(headA, headB *ListNode) *ListNode {
    lenA := 0
    lenB := 0
    temA := headA
    temB := headB
    for temA !=nil {
        temA = temA.Next
        lenA++
    }
    for temB !=nil {
        temB = temB.Next
        lenB++
    }
    if lenA >= lenB {
        diff := lenA - lenB
        for i:=0; i<diff; i++ {
            headA = headA.Next
        }
    } else {
        diff := lenB - lenA
        for i:=0; i<diff; i++ {
            headB = headB.Next
        }
    }
    for headB != headA {
        headA = headA.Next
        headB = headB.Next
    }
    return headA
}